package com.hcy.MovieData;

import com.jch.Index;
import com.wl.代码.Move_room;
import javafx.scene.layout.Background;

import javax.swing.*;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import java.awt.*;
import java.awt.event.*;

public class Background_server extends JFrame {

    private JPanel jP_Left;//左面板
    private JPanel jp_right;//右面板
    //显示一个小手
    private Cursor hand = new Cursor(Cursor.HAND_CURSOR);

     public Background_server(){
         setTitle("电影购票后台管理系统");
         setSize(930,600);

         //左面板
         jP_Left = new JPanel();
         jP_Left.setLayout(null);// 设置为绝对布局
         jP_Left.setOpaque(true);// 将右边面板的背景设置为透明
         jP_Left.setBackground(new Color(116, 176, 236, 255));// 背景颜色
         jP_Left.setPreferredSize(new Dimension(130, 600));// 设置边界布局的所站的大小

         //右面板
         jp_right = new JPanel();
         jp_right.setLayout(null);// 设置为绝对布局
//         jp_right.setOpaque(true);// 将右边面板的背景设置为透明
//         jp_right.setBackground(new Color(173,216,230));
         jp_right.setPreferredSize(new Dimension(800, 600));// 设置边界布局的所站的大小

         //背景
         JLabel jl_bj = new JLabel();
         jl_bj.setOpaque(true);// 将右边面板的背景设置为透明
         jl_bj.setBounds(0,0,800,600);
         jl_bj.setBackground(new Color(173,216,230));
         jp_right.add(jl_bj);

         //背景——字
         JLabel jl_word = new JLabel("欢迎进入后台服务系统");
         jl_word.setFont(new Font("楷体",Font.PLAIN,50));
         jl_word.setForeground(new Color(0,0,0));
         jl_word.setBounds(100,200,600,50);
         jl_bj.add(jl_word);

         add(BorderLayout.EAST,jp_right);


         //按钮
         JLabel jl_sign_out = new JLabel("[安全退出]");
         jl_sign_out.setFont(new Font("楷体",Font.PLAIN,12));
         jl_sign_out.setOpaque(false);
         jl_sign_out.setCursor(hand);// 放上去显示小手
         jl_sign_out.setForeground(Color.WHITE);
         jl_sign_out.setBounds(5,10,58,30);
         jl_sign_out.addMouseListener(new MouseAdapter() {

             @Override
             public void mouseEntered(MouseEvent e) {
                 jl_sign_out.setForeground(Color.YELLOW);
             }

             @Override
             public void mouseExited(MouseEvent e) {
                 jl_sign_out.setForeground(Color.WHITE);
             }

             @Override
             public void mouseClicked(MouseEvent e) {
                 JDialog dialog = new JDialog();
                 dialog.setSize(300,220);

                 //背景
                 JLabel jl_brougd = new JLabel(new ImageIcon(Move_room.class.getResource("返回背景.jpg")));
                 jl_brougd.setBounds(0,0,300,220);
                 dialog.add(jl_brougd);

                 //否-按钮
                 JButton jb_No = new JButton("否");
                 jb_No.setOpaque(false);
                 jb_No.setForeground(Color.BLACK);
                 jb_No.setBounds(20,170,60,30);
                 jb_No.addMouseListener(new MouseAdapter() {
                     @Override
                     public void mouseClicked(MouseEvent e) {
                         dialog.dispose();
                     }
                 });

                 jb_No.registerKeyboardAction(new ActionListener() {
                     @Override
                     public void actionPerformed(ActionEvent e) {
                         dialog.dispose();
                     }
                     },KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0),
                         JComponent.WHEN_IN_FOCUSED_WINDOW);

                 jl_brougd.add(jb_No);


                 //提示
                 JLabel jl_Tips = new JLabel("⚠是否退出");
                 jl_Tips.setOpaque(false);
                 jl_Tips.setFont(new Font("微软雅黑",Font.PLAIN,16));
                 jl_Tips.setForeground(new Color(220,20,60));
                 jl_Tips.setBounds(100,60,240,40);
                 jl_brougd.add(jl_Tips);


                 //是-按钮
                 JButton jb_Yes = new JButton("是");
                 jb_Yes.setOpaque(false);
                 jb_Yes.setForeground(Color.BLACK);
                 jb_Yes.setBounds(220,170,60,30);
                 jb_Yes.addMouseListener(new MouseAdapter() {
                     @Override
                     public void mouseClicked(MouseEvent e) {
                        System.exit(-1);
                     }
                 });

                 jb_No.registerKeyboardAction(new ActionListener() {
                     @Override
                     public void actionPerformed(ActionEvent e) {
                         System.exit(-1);
                     }
                     },KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0),
                         JComponent.WHEN_IN_FOCUSED_WINDOW);

                 jl_brougd.add(jb_Yes);

                 dialog.setResizable(false);
                 dialog.setLocationRelativeTo(null);
                 dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                 dialog.setVisible(true);

             }
         });
         jP_Left.add(jl_sign_out);

         JLabel jl_return = new JLabel("[返回首页]");
         jl_return.setFont(new Font("楷体",Font.PLAIN,12));
         jl_return.setOpaque(false);
         jl_return.setCursor(hand);// 放上去显示小手
         jl_return.setForeground(Color.WHITE);
         jl_return.setBounds(70,10,58,30);
         jl_return.addMouseListener(new MouseAdapter() {

             @Override
             public void mouseEntered(MouseEvent e) {
                 jl_return.setForeground(Color.YELLOW);
             }

             @Override
             public void mouseExited(MouseEvent e) {
                 jl_return.setForeground(Color.WHITE);
             }

             @Override
             public void mouseClicked(MouseEvent e) {
                 JDialog dialog = new JDialog();
                 dialog.setSize(300,220);

                 //背景
                 JLabel jl_brougd = new JLabel(new ImageIcon(Move_room.class.getResource("返回背景.jpg")));
                 jl_brougd.setBounds(0,0,300,220);
                 dialog.add(jl_brougd);

                 //否-按钮
                 JButton jb_No = new JButton("否");
                 jb_No.setOpaque(false);
                 jb_No.setForeground(Color.BLACK);
                 jb_No.setBounds(20,170,60,30);
                 jb_No.addMouseListener(new MouseAdapter() {
                     @Override
                     public void mouseClicked(MouseEvent e) {
                         dialog.dispose();
                     }
                 });

                 jb_No.registerKeyboardAction(new ActionListener() {
                     @Override
                     public void actionPerformed(ActionEvent e) {
                         dialog.dispose();
                     }
                     },KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0),
                         JComponent.WHEN_IN_FOCUSED_WINDOW);

                 jl_brougd.add(jb_No);


                 //提示
                 JLabel jl_Tips = new JLabel("⚠是否返回首页");
                 jl_Tips.setOpaque(false);
                 jl_Tips.setFont(new Font("微软雅黑",Font.PLAIN,16));
                 jl_Tips.setForeground(new Color(220,20,60));
                 jl_Tips.setBounds(100,60,240,40);
                 jl_brougd.add(jl_Tips);


                 //是-按钮
                 JButton jb_Yes = new JButton("是");
                 jb_Yes.setOpaque(false);
                 jb_Yes.setForeground(Color.BLACK);
                 jb_Yes.setBounds(220,170,60,30);
                 jb_Yes.addMouseListener(new MouseAdapter() {
                     @Override
                     public void mouseClicked(MouseEvent e) {
                         dialog.dispose();
                         dispose();
                         new Index();
                     }
                 });

                 jb_No.registerKeyboardAction(new ActionListener() {
                     @Override
                     public void actionPerformed(ActionEvent e) {
                         dialog.dispose();
                         dispose();
                         new Index();
                     }
                     },KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0),
                         JComponent.WHEN_IN_FOCUSED_WINDOW);

                 jl_brougd.add(jb_Yes);

                 dialog.setResizable(false);
                 dialog.setLocationRelativeTo(null);
                 dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                 dialog.setVisible(true);

             }
         });
         jP_Left.add(jl_return);

         //用户管理
         JLabel jl_user = new JLabel(".用户管理",JLabel.CENTER);
         jl_user.setFont(new Font("楷体",Font.PLAIN,14));
         jl_user.setOpaque(false);
         jl_user.setCursor(hand);// 放上去显示小手
         jl_user.setForeground(Color.WHITE);
         jl_user.setBounds(35,40,60,30);
         jl_user.addMouseListener(new MouseAdapter() {

             @Override
             public void mouseEntered(MouseEvent e) {
                 jl_user.setForeground(Color.YELLOW);
             }

             @Override
             public void mouseExited(MouseEvent e) {
                 jl_user.setForeground(Color.WHITE);
             }

             @Override
             public void mouseClicked(MouseEvent e) {
                 if (e.getClickCount() == 1){

                     //清楚面板里面的组件
                     jl_bj.removeAll();
                     //获取重新重绘的面板并加入jlable
                     JPanel jp_user = User();
                     jl_bj.add(jp_user);

                     //刷新面板里面组件并重新重绘上去
                     jl_bj.repaint();
                     jl_bj.revalidate();

                 }
             }
         });
         jP_Left.add(jl_user);

         //线——背景
         JLabel jl_Line = new JLabel();
         jl_Line.setOpaque(true);
         jl_Line.setBackground(Color.WHITE);
         jl_Line.setBounds(0,70,130,2);
         jP_Left.add(jl_Line);

         //购票管理
         JLabel jl_purchase = new JLabel(".购票管理",JLabel.CENTER);
         jl_purchase.setFont(new Font("楷体",Font.PLAIN,14));
         jl_purchase.setOpaque(false);
         jl_purchase.setCursor(hand);// 放上去显示小手
         jl_purchase.setForeground(Color.WHITE);
         jl_purchase.setBounds(35,70,60,30);
         jl_purchase.addMouseListener(new MouseAdapter() {

             @Override
             public void mouseEntered(MouseEvent e) {
                 jl_purchase.setForeground(Color.YELLOW);
             }

             @Override
             public void mouseExited(MouseEvent e) {
                 jl_purchase.setForeground(Color.WHITE);
             }

             @Override
             public void mouseClicked(MouseEvent e) {
                 if (e.getClickCount() == 1){

                     //清楚面板里面的组件
                     jl_bj.removeAll();
                     //获取重新重绘的面板并加入jlable
                     JPanel jp_purchase = Purchase();
                     jl_bj.add(jp_purchase);

                     //刷新面板里面组件并重新重绘上去
                     jl_bj.repaint();
                     jl_bj.revalidate();

                 }
             }
         });
         jP_Left.add(jl_purchase);

         //线——背景
         JLabel jl_Line1 = new JLabel();
         jl_Line1.setOpaque(true);
         jl_Line1.setBackground(Color.WHITE);
         jl_Line1.setBounds(0,100,130,2);
         jP_Left.add(jl_Line1);

         add(BorderLayout.WEST,jP_Left);



         setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
         setLocationRelativeTo(null);
         setResizable(false);
         setVisible(true);
     }

     public JPanel User(){
         JPanel jp_user = new JPanel();
         jp_user.setSize(800,600);
         jp_user.setVisible(true);

         //背景
         JLabel jl_brougd = new JLabel(new ImageIcon(Background_server.class.getResource("用户背景.jpg")));
         jl_brougd.setBounds(0,0,800,600);

         jp_user.add(jl_brougd);

         return jp_user;
     }

    public JPanel Purchase(){
        JPanel jp_purchase = new JPanel();
        jp_purchase.setSize(800,600);
        jp_purchase.setVisible(true);

        //背景
        JLabel jl_brougd = new JLabel(new ImageIcon(Background_server.class.getResource("购买背景.jpg")));
        jl_brougd.setBounds(0,0,800,600);

        jp_purchase.add(jl_brougd);
        return jp_purchase;
    }

    public static void main(String[] args) {
        new Background_server();
    }
}
